package com.yuzhyn.hiops.app.application.schedule;

import com.yuzhyn.hiops.common.model.SystemStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.yuzhyn.azylee.core.systems.linuxs.status.LinuxSystemStatusTool;

@Slf4j
@Component
@EnableScheduling
@EnableAsync
public class SystemStatusSchedule {


    // 线程池
    // https://bbs.csdn.net/topics/350108321

    SystemStatus systemStatus = new SystemStatus();

    @Async
    @Scheduled(cron = "0/60 * * * * *")
    public void show() {
        Thread t = Thread.currentThread();
        systemStatus.setAfk(0L);
        systemStatus.setCpu((int) LinuxSystemStatusTool.getCpuUseRatio());
        systemStatus.setRam(LinuxSystemStatusTool.getRam().getMemFree());
        log.info(systemStatus.toString());

        systemStatus = new SystemStatus();
    }

//    @Scheduled(cron = "0/1 * * * * *")
//    public void show1() {
//        Map<Thread, StackTraceElement[]> maps = Thread.getAllStackTraces();
//        if (maps != null) {
//        }
//    }
//
//    @Scheduled(cron = "0/5 * * * * *")
//    public void show2() {
//        Thread t = Thread.currentThread();
//        Sleep.s(5);
//        log.info("SystemStatusSchedule" + new Date() + " : 5秒间隔 Scheduled :" + t.getId() + "," + t.getName());
//    }
}
